package ch02;

public class Example2_4 {
    public static void main(String[] args) throws Exception {
        System.out.println("请输入单链表中的10个结点值:");
        LinkList L = new LinkList(10,true);
        System.out.println("删除重复结点前单链表中的各个结点值为:");
        L.display();
        removeRepeatElem(L);
        System.out.println("删除重复结点后单链表中的各个结点值为:");
        L.display();
    }

    private static void removeRepeatElem(LinkList L) throws Exception{
        Node p = L.head.next, q;
        while (p != null) {
            int order = L.indexOf(p.data);
            q = p.next;
            while (q != null) {
                if ((p.data).equals(q.data))
                    L.remove(order + 1);
                else
                    ++order;
                q = q.next;
            }
            p = p.next;
        }
    }
}
